ABC289 D - Step Up Robot
https://atcoder.jp/contests/abc289/tasks/abc289_d
提出
code: python
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
x = int(input())
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# . . . .
# 0 1 2 3 4 5 6 7 8
# . . . .
# dpij: iステップをj回使って到達するかどうか
dp = [[0 for _ in range(x+1+b-1)] for _ in range(x+1+b-1)]
dp00 = 1
print(dp)
解答
code: python
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
x = int(input())
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# . . . .
# 0 1 2 3 4 5 6 7 8
# . . . .
# もちの存在を管理
ok = True for _ in range(10**5+10)
for i in b:
oki = False
dp = False for _ in range(x+1)
dp0 = True
for i in range(x):
# i段目に到達可能なら
if dpi:
# ステップ(n <= 10)を踏んでいく ステップを使う回数の制限はない
for step in a:
# もちがなければ遷移可能
if i+step <= x and oki+step:
dpi+step = True
if dpx:
print("Yes")
else:
print("No")
テーマ
#dp
メモ
https://qiita.com/Waaaa1471/items/9cd2583f1fcd63662bbf#dstep-up-robot
提出
code: python
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = set(list(map(int, input().split())))
x = int(input())
dp = False * (x+1)
dp0 = True
for i in range(1, x+1):
for j in a:
if i - j >= 0:
if dpi-j and i-j not in b:
dpi = True
print("Yes") if dpx else print("No")